<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<link rel="shortcut icon" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/logo.png"/>
	<title>充值</title>
	<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/mui.min.js"></script>
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/css/mui.min.css" rel="stylesheet" />
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/css/other/all.css" rel="stylesheet" />
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/css/other/app.css?a" rel="stylesheet" />
</head>
<body>
	<div class="recharge mt-0">
		<div class="commodity_details payway mt-0">
			<div class="commodity">
				<ul class="mui-table-view">
					<li class="mui-table-view-cell mui-media checkli" data-type="1">
						<img class="mui-media-object mui-pull-left" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/my/wechatpay.png">
						<div class="mui-media-body">
							微信支付
							<p class="mui-ellipsis">微信平台仅支持微信支付</p>
						</div>
						<img class="pic" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/cart/checked3.png">
						<input class="check" type="radio" name="f" checked="checked">
					</li>
					<li class="mui-table-view-cell mui-media checkli" data-type="2">
						<img class="mui-media-object mui-pull-left" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/my/zfb.png">
						<div class="mui-media-body">
							支付宝支付
							<p class="mui-ellipsis">支付宝支付，更安全，更放心</p>
						</div>
						<img class="pic" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/cart/checked1.png">
						<input class="check" type="radio" name="">
					</li>
				</ul>
			</div>
		</div>
		<div class="mui-input-row">
			<label>金额</label>
			<input type="tel" id="money" class="mui-input-clear" placeholder="请输入充值金额" data-input-clear="5"><span class="mui-icon mui-icon-clear mui-hidden"></span>
		</div>
		<p>
			<button id="cz">充值</button>
		</p>
	</div>
</body>
</html>
{{template "wechat/public/share.html" .}}
<script>
	var type=1
    var checkli = document.getElementsByClassName("checkli");
    for(var i = 0; i < checkli.length; i++){
		checkli[i].onclick = function() {
			for(var i = 0; i < checkli.length; i++){
				checkli[i].getElementsByClassName('pic')[0].src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/cart/checked1.png";
				checkli[i].getElementsByClassName('check')[0].checked=false;
			}
			this.getElementsByClassName('pic')[0].src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/cart/checked3.png";
			this.getElementsByClassName('check')[0].checked=true;
			type=this.getAttribute("data-type")
		}
	}
	document.getElementById('cz').addEventListener('tap',function(){
		var money=document.getElementById('money').value
		if(type==1){
			{{if eq .mem.wx_openid_gzh ""}}
			mui.confirm("您还未绑定微信,是否前往绑定?","提示",function(res){
				if(res.index){
					mui.closePopups()
					window.location.href='/mobile/bind_wechat_oauth'
				}else{
					return false;
				}
			});
			{{end}}
		}
		if(money>={{.system.recharge}}){
			mui.ajax(window.location.href,{
				type:'post',
				data:{money:money,type:type},
				success:function(res){
					console.log(res)
					if(res.status==1){
						if(type==1){
							if(res.style==1){
								var payparms=res.res
								console.log(payparms)
								wx.chooseWXPay({
									timestamp: payparms.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
									nonceStr: payparms.nonceStr, // 支付签名随机串，不长于 32 位
									package: payparms.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\*\*\*）
									signType: 'MD5', // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
									paySign: payparms.paySign, // 支付签名
									success: function (res) {
										mui.toast("充值成功")
									}
								});
							}else{
								window.location.href=res.res
							}
						}else{
							// console.log(res.res)
							window.location.href=res.res
						}	
					}else if(res.status==0){
						mui.toast("网络繁忙,请稍后再试~")
					}
				}
			})
		}else{
			mui.toast("一次需充值{{.system.recharge}}以上~")
		}
	})
</script>